package main

import "fmt"

//#link: https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/
func main() {
	nums := []int{5, 7, 7, 8, 8, 10}
	target := 8
	fmt.Println(search(nums, target))
}
func search(nums []int, target int) int {
	edge := [2]int{}
	left, right := 0, len(nums)
	for left < right {
		mid := left + (right-left)>>1
		if nums[mid] < target {
			left = mid + 1
		} else if nums[mid] > target {
			right = mid
		} else {
			for left <= mid {
				if nums[left] == target {
					edge[0] = left
					break
				}
				left++
			}

			for right >= mid {
				if nums[right-1] == target {
					edge[1] = right
					break
				}
				right--
			}
			break
		}
	}
	return right - left
}
